<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="strategyCatalog"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <select name="strategyId" class="form-control">
                    <#list strategys as s>
                        <option value="${s.id}">${s.title}</option>
                    </#list>
                </select>
                <script>
                    $("select[name='strategyId']").val(${qo.strategyId!});
                </script>

                <a role="button" class="btn btn-success searchBtn">
                    <span class="glyphicon glyphicon-search"></span>查询
                </a>
                <a role="button" class="btn btn-success updateBtn">
                    <span class="glyphicon glyphicon-pencil"></span>添加
                </a>
            </form>
            <table class="table table-striped table-hover" >
                <thead>
                <tr>
                    <th>编号</th>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                </tr>

                </thead>
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.name}</td>
                       <td>${entity.strategy.title}</td>
                       <td>${entity.sequence}</td>
                       <td>${entity.state?string("启用","禁用")}</td>
                        <td>
                            <a role="button" class="btn btn-xs btn-success updateBtn" data-json='${entity.json!}'>
                                <span class="glyphicon glyphicon-pencil"></span>修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增攻略推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id" />
                    <div class="form-group">
                        <label class="col-sm-4 control-label">分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <select name="strategy.id" class="form-control">
                                <#list strategys as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control">
                                <option value="true">启用</option>
                                <option value="false">禁用</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary strategyCatalogSubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        //给查询按钮绑定点击事件
       $(".searchBtn").click(function () {
           //提交表单
           $("#searchForm").submit();
       });
       //修改按钮的点击事件
       $(".updateBtn").click(function () {
           $("#editForm input").val("");
           $("#editForm select").val("");
           var json = $(this).data("json");
           if (json) {
               $("#editForm input[name='name']").val(json.name);
               $("#editForm input[name='id']").val(json.id);
               $("#editForm input[name='sequence']").val(json.sequence);
               $("#editForm select[name='strategy.id']").val(json.strategyId);
               $("#editForm select[name='state']").val(json.state+"");

           }
           $("#inputModal").modal("show");

       });
        $("#editForm").ajaxForm(function (data) {
            if (data.success) {
                reload();
            }
        });
        //模态框按钮的点击事件
        $(".strategyCatalogSubmitBtn").click(function () {

            $("#editForm").submit();
        });
    });
</script>
<style>
    #contentModal img{
        width: 100%;
    }
</style>
</body>
</html>